package org.example;

import java.util.Scanner;

//找出消失的数字
class Solution {
    public void rotate(int[] nums, int k) {
        //2 3 4 5 6 -> 6 2 3 4 5
        int new_k = k % nums.length;
        for (int i = 1; i <= new_k; i++) {
            int temp = nums[nums.length - 1];//保留最后一位,6
            for (int j = nums.length - 2; j >= 0; j--) {//从后往前遍历
                nums[j + 1] = nums[j];
                //当j=3,nums[4]=num[3]=5
                //当j=2,nums[3]=num[2]=4
                //当j=1,nums[2]=num[1]=3
                //当j=0,nums[1]=num[0]=2
                //临时变量temp中的放在num[0]=temp
            }
            nums[0] = temp;
        }
    }
    /*public int missingNum(int[] nums) {
        //原本和应该是ExceptedSum,但实际上是RealSum,所以差值就是少的那个数字
        int ExpectedSum = (nums.length) * (nums.length + 1) / 2;
        //预想的和=(首项+末项)*项数/2,(0+nums.length)*(nums.length+1)/2
        int RealSum = 0;
        for (int i = 0; i < nums.length; i++) {
            RealSum += nums[i];
        }
        *//*System.out.println(RealSum);
        System.out.println(ExpectedSum);
        System.out.println(nums.length);*//*
        return ExpectedSum - RealSum;
    }*/
}
public class Test2 {
    //1 2 3 4 ,10,0 1 2 3,nums.length=4
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("输入数组：");
        String input = in.nextLine();
        //分割字符串
        String[] str = input.split(",");
        int[] arr = new int[str.length];
        for (int i = 0; i < str.length; i++) {
            arr[i] = Integer.parseInt(str[i]);//将字符串转化为整型
        }
        Scanner input_k = new Scanner(System.in);
        System.out.println("输入k值：");
        int k = input_k.nextInt();
        Solution solution = new Solution();
        solution.rotate(arr, k);
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        //System.out.println(solution.missingNum(arr));
        in.close();
    }
}
